using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;


namespace Pampa.Grid.UI.CustomControls
{
    public class BasicPager : AbstractPager
    {
        private string pathImages;

        public BasicPager() : base()
        {
            this.PathImages = "Pampa.Grid" + GetImagesPath();
        }

        public string PathImages
        {
            get { return pathImages; }
            set { pathImages = value; }
        }

        public string PageText
        {
            get; set;
        }

        public string FromText
        {
            get; set;
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            CustomGrid parentList = CustomGrid.LoadFromSession(this.GridID);

            if (parentList.PageSize == 0)
                return;

            string pageText = this.PageText ?? Resources.CustomGrid.Page;
            string fromText = this.FromText ?? Resources.CustomGrid.From;

            writer.AddAttribute("id", this.ID);
            writer.AddAttribute("class", this.CssClass);
            writer.AddStyleAttribute("width", this.Width.ToString());
            writer.AddStyleAttribute("display", this.Show ? "" : "none");

            writer.RenderBeginTag(HtmlTextWriterTag.Div);

            writer.WriteLine("<table>");
            writer.WriteLine("<tr>");

            writer.WriteLine("<td align=\"right\">");
            writer.WriteLine("<table><tr>");
            writer.WriteLine("<td><img src=\"" + GetResourceUrl(this.PathImages) + "/btnFirst.gif\" srcOn=\"" + GetResourceUrl(this.PathImages) + "/btnFirstOn.gif\" onmouseover=\"Common.on(this)\" onmouseout=\"Common.off(this)\" onclick=\"ClientPager_moveFirst('" + this.ID + "')\" style=\"cursor:pointer\"></td>");
            writer.WriteLine("<td><img src=\"" + GetResourceUrl(this.PathImages) + "/btnPrevious.gif\" srcOn=\"" + GetResourceUrl(this.PathImages) + "/btnPreviousOn.gif\" onmouseover=\"Common.on(this)\" onmouseout=\"Common.off(this)\" onclick=\"ClientPager_movePrevious('" + this.ID + "')\" style=\"cursor:pointer\"></td>");
            writer.WriteLine("<td align=\"left\" id=\"counter_" + this.ID + "\" class=\"pages\">");
            writer.WriteLine(" " + pageText + " " + parentList.PageNumber.ToString() + " " + fromText + " " + parentList.LastPage.ToString() + " ");
            writer.WriteLine("</td>");
            writer.WriteLine("<td><img src=\"" + GetResourceUrl(this.PathImages) + "/btnNext.gif\" srcOn=\"" + GetResourceUrl(this.PathImages) + "/btnNextOn.gif\" onmouseover=\"Common.on(this)\" onmouseout=\"Common.off(this)\" onclick=\"ClientPager_moveNext('" + this.ID + "')\" style=\"cursor:pointer\"></td>");
            writer.WriteLine("<td><img src=\"" + GetResourceUrl(this.PathImages) + "/btnLast.gif\" srcOn=\"" + GetResourceUrl(this.PathImages) + "/btnLastOn.gif\" onmouseover=\"Common.on(this)\" onmouseout=\"Common.off(this)\" onclick=\"ClientPager_moveLast('" + this.ID + "')\" style=\"cursor:pointer\"></td>");
            writer.WriteLine("</tr></table>");
            writer.WriteLine("</td>");

            writer.WriteLine("</tr>");
            writer.WriteLine("</table>");

            writer.RenderEndTag();
        }

        protected override void RenderProperties(HtmlTextWriter writer)
        {
            base.RenderProperties(writer);

            string pageText = this.PageText ?? Resources.CustomGrid.Page;
            string fromText = this.FromText ?? Resources.CustomGrid.From;

            writer.WriteLine("obj" + this.ID + ".refresh = BasicPager_refresh;");
            writer.WriteLine("obj" + this.ID + ".strFrom = '" + fromText + "';");
            writer.WriteLine("obj" + this.ID + ".strPage = '" + pageText + "';");
        }
    }
}
